function [] = writeToDatabase( filename, fileformat )
%     conn = database('MySql','root','primetrader', 'com.mysql.jdbc.Driver', ...
%    'jdbc:mysql://localhost:3306/obx');
    conn = database('MySql','root','primetrader');
    
    fid = fopen( filename );
    fgetl(fid);
    C = textscan(fid, '%s %s %s %s', 'delimiter', '$', ...
                 'EmptyValue', -Inf);
    fclose(fid);
    exdata = {};
    for i = 1:size(C{1,1},1)
        temp_ticker = C{1,1}{i};
        exdata{i,1} = temp_ticker(1:end-1) ;
        
        temp_timestamp = C{1,2}{i};
        temp_timestamp = temp_timestamp(2:end-1);
        %'YYYY-MM-DD HH:MM:SS'
        if length(temp_timestamp) == 5
            exdata{i,2} = [datestr(today,'yyyy-mm-dd') ' ' temp_timestamp(1) ':'...
                temp_timestamp(2:3) ':' temp_timestamp(4:5)] ;
        else
            exdata{i,2} =  [datestr(today,'yyyy-mm-dd') ' ' temp_timestamp(1:2) ':'...
                temp_timestamp(3:4) ':' temp_timestamp(5:6)] ;
        end
        
        temp_bid = C{1,3}{i};
        temp_ask = C{1,4}{i};
        exdata{i,3} = temp_bid(2:end-1);
        exdata{i,4} = temp_ask(2:end-1);
    end   
    
    switch fileformat
        case 0
            colnames = {'ticker' 'orderTime' 'orderBid' 'orderAsk'};
%             colnames = {'ticker'; 'orderTime'; 'orderBid'; 'orderAsk'};
            insert(conn, 'orderbook', colnames, exdata )
        case 1
            
        case 2
    end
    
    close(conn);
    
end